// pages/recruitChangeIdentity/recruitChangeIdentity.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imageUrl,
    myIsRcruit:false,
    detail:'',
    userInfo:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    this.getUserIdentity();
  },
  getUserIdentity: function () {
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'recruitPersonalInfo/getOne', //仅为示例，并非真实的接口地址
      data: { userId: this.data.userInfo.id },
      success: function (res) {
        if (res.data.success) {
          if (res.data.data) {
            that.setData({
              myIsRcruit: res.data.data.userCharacter == '招聘' ? true : false,
              detail: res.data.data
            })
 
          }
        }
      }
    })
  },
  changeIdentify:function(e){
    var that=this;
    wx.request({
      url: app.globalData.httpApiCar + 'recruitPersonalInfo/update', //仅为示例，并非真实的接口地址
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        id: this.data.detail.id,
        userCharacter: this.data.myIsRcruit ? '求职' :'招聘'
      },
      success: function (res) {
        if (res.data.success) {
          if (!that.data.myIsRcruit){
            if (that.data.detail.onCompanyName){
              wx.navigateBack({
                delta: 1
              })
            }else{
              wx.redirectTo({
                url: '/pages/recruitBasicInfo/recruitBasicInfo',
              })
            }
          }else{
            wx.navigateBack({
              delta:1
            })
          }
          
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})